package handler;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.hn.comm.excel.ExcelHandler;
import com.hn.comm.excel.ExcelModel;
import com.hn.shoutchinese.pinying.service.impl.PinyingServiceImpl;

public class DeleteRepeatWordHandler extends BaseHandler {

	public void startWork() {
		DeleteRepeatWordHandler ph = new DeleteRepeatWordHandler();

		PinyingServiceImpl ps = new PinyingServiceImpl();
		ExcelModel eModel = ExcelHandler.getExcelData(BaseHandler
				.getExcelFile());

		// 修正的内容
		List<Map<String, String>> fixContent = new ArrayList<Map<String, String>>();

		// 重复个数
		int iRepeatCount = 0;

		// 得到单个
		for (Map<String, String> map : eModel.getContent()) {
			// 得到单词
			String chinese = map.get(HEAD_CHINESE);
			// 如果修正的不存在，那么加入
			boolean exist = false;
			for (Map<String, String> fixMap : fixContent) {
				if (fixMap.get(HEAD_CHINESE).equals(chinese)) {
					exist = true;
					iRepeatCount++;
					System.out.println("重复单词为:" + chinese);
					break;
				}
			}

			if (!exist) {
				fixContent.add(map);
			}
		}
		eModel.setContent(fixContent);

		ExcelHandler.writeExcel(eModel, BaseHandler.getExcelFile());
		System.out.println("总共删除重复单词 " + iRepeatCount);
		System.out.println("删除重复单词完成。。。。。");
	}

	public static void main(String[] args) {
		DeleteRepeatWordHandler ph = new DeleteRepeatWordHandler();
		ph.startWork();
	}
}
